package testdemo;

import dao.AnnotationDao;
import javabean.House;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

import static tools.Dbutils.getSqlSession;
import static tools.Dbutils.logs;

public class TestAnnotation {
    @Before
    public void auto1(){

    }
    @After
    public void auto2(){

    }
    @Test
    public void findAll(){
        logs();
        SqlSession sqlSession = getSqlSession();
        AnnotationDao mapper = sqlSession.getMapper(AnnotationDao.class);
        List<House> all = mapper.findAll();
        for(House h : all){
            System.out.println(h);
        }
    }
    @Test
    public void findOne(){
        logs();
        SqlSession sqlSession = getSqlSession();
        AnnotationDao mapper = sqlSession.getMapper(AnnotationDao.class);
        House one = mapper.findOne(15);
        System.out.println(one);
    }
    @Test
    public void insert(){
        logs();
        SqlSession sqlSession = getSqlSession();
        AnnotationDao mapper = sqlSession.getMapper(AnnotationDao.class);
        House house = new House();
        house.setName("问天");
        house.setTel("987");
        house.setAddress("云南");
        house.setRent("4000");
        house.setState("1");
        mapper.insert(house);
        sqlSession.commit();
        sqlSession.close();
    }

    @Test
    public void update(){
        logs();
        SqlSession sqlSession = getSqlSession();
        AnnotationDao mapper = sqlSession.getMapper(AnnotationDao.class);
        House house = new House();
        house.setName("问雅");
        house.setId(15);
        mapper.update(house);
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void delete(){
        logs();
        SqlSession sqlSession = getSqlSession();
        AnnotationDao mapper = sqlSession.getMapper(AnnotationDao.class);
        mapper.delete(13);
        sqlSession.commit();
        sqlSession.close();
    }
}
